cc.Class({
    extends: cc.Component,

    properties: {
        startx: "int",
        starty: "int",
        otherHuoChai:cc.node,
    },

    // use this for initialization
    onLoad: function () {

        cc.director.getCollisionManager().enabled = true;
        //cc.director.getCollisionManager().enabledDebugDraw = true;
        //cc.director.getCollisionManager().enabledDrawBoundingBox = true;

        this.startx = this.node.x;
        this.starty = this.node.y;

        this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
            //this.opacity = 255;
            if(this.opacity==255)
            {
                var delta = event.touch.getDelta();
                this.x += delta.x;
                this.y += delta.y;
            }
            
        }, this.node);

        this.node.on(cc.Node.EventType.TOUCH_END, function (event) {

            this.node.x = this.startx;
            this.node.y = this.starty;
            
            if(this.otherHuoChai!=null)
            {
                if(this.node.opacity = 255 && this.otherHuoChai.node.opacity == 0)
                {
                    this.node.opacity = 0;
                    this.otherHuoChai.node.opacity = 255;
                }else
                {
                    this.node.opacity = 255;
                }
            }
            
        }, this);
    },

    onCollisionEnter: function (other) {
        //this.node.color = cc.Color.RED;
       // console.log('onCollisionEnter============'+this.name);
        this.otherHuoChai = other;
       
    },

    onCollisionStay: function (other) {
         //console.log('on collision stay');
         this.otherHuoChai = other;
    },

    onCollisionExit: function () {
        //this.node.color = cc.Color.WHITE;
        this.otherHuoChai =null;

    },


    // called every frame
    update: function (dt) {

    },
});